#!/bin/bash

version=v1.1.2

case "$arch" in
"64") wget https://github.com/Orama-Interactive/Pixelorama/releases/download/${version}/Pixelorama-Linux-ARM64.tar.gz -O /tmp/pixelorama.tar.gz || error "Could not download Pixelorama archive" ;;
"32") wget https://github.com/Orama-Interactive/Pixelorama/releases/download/${version}/Pixelorama-Linux-ARM32.tar.gz -O /tmp/pixelorama.tar.gz || error "Could not download Pixelorama archive" ;;
*) error "Failed to detect OS CPU architecture! Something is very wrong." ;;
esac

sudo rm -rf /usr/share/Pixelorama /usr/share/applications/com.orama_interactive.Pixelorama.desktop /usr/bin/pixelorama
sudo tar -xvf /tmp/pixelorama.tar.gz -C /tmp/
case "$arch" in
"64") sudo mv /tmp/Pixelorama-Linux-ARM64/ /usr/share/Pixelorama/ || error "Could not install Pixelorama" ;;
"32") sudo mv /tmp/Pixelorama-Linux-ARM32/ /usr/share/Pixelorama/ || error "Could not install Pixelorama" ;;
*) error "Failed to detect OS CPU architecture! Something is very wrong." ;;
esac
rm -f /tmp/pixelorama.tar.gz

case "$arch" in
"64") sudo ln -s /usr/share/Pixelorama/Pixelorama.arm64 /usr/bin/pixelorama || error "Could not create symbolic link" ;;
"32") sudo ln -s /usr/share/Pixelorama/Pixelorama.arm32 /usr/bin/pixelorama || error "Could not create symbolic link" ;;
*) error "Failed to detect OS CPU architecture! Something is very wrong." ;;
esac

echo "[Desktop Entry]
Name=Pixelorama
GenericName=2D sprite editor
GenericName[el]=Επεξεργαστής δισδιάστατων εικόνων
GenericName[fr]=Éditeur de sprites 2D
GenericName[pt_BR]=Editor de sprites 2D
GenericName[zh_CN]=2D 精灵编辑器
Comment=Create and edit static or animated 2D sprites
Comment[el]=Δημιουργήστε και επεξεργαστείτε στατικές ή κινούμενες δισδιάστατες εικόνες
Comment[fr]=Créez et modifiez des sprites 2D statiques ou animées
Comment[pt_BR]=Crie e edite sprites 2D estáticos ou animados
Comment[zh_CN]=创建并编辑 2D 精灵图片或动画
Exec=pixelorama
Icon=$(dirname "$0")/icon-64.png
Terminal=false
Type=Application
Categories=Graphics;2DGraphics;RasterGraphics;" | sudo tee /usr/share/applications/com.orama_interactive.Pixelorama.desktop
